import { createRouter, createWebHistory } from "vue-router";
import Login from '@/views/Login/index.vue';
import Layout from '@/views/Layout/index.vue';
import Home from '@/views/Home/index.vue';
import Category from '@/views/Category/index.vue';
import SubCategory from '@/views/SubCategory/index.vue';

// 创建路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Layout',
      component: Layout,

      
      children: [
        {
          path: "", // 默认二级路由
          component: Home,
        },
        {
          path: 'category/:id', // 一级分类
          component: Category
        },
        {
          path: 'category/sub/:id', // 二级分类
          component: SubCategory
        }
      ]
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    }
  ],
  //路由滚动行为定制
  scrollBehavior() {
    return { top: 0 }
  }
})

// 导出
export default router;